from app.aoduo_admin.models import AdminGroup
from rest_framework.views import APIView
from django.http import JsonResponse
from common.authCheck.adminAuth import getAdminUser, check_admin_login
from common.dictInfo import model_to_dict
from common.paginator import paginator
from .chiefAdminAuthVerify import chiefAdminCheck


class AdminGroupListView(APIView):

    @check_admin_login
    @chiefAdminCheck
    def get(self, request):
        """
        获取用户组列表
        :param request:
        :return:
        """
        fields = ['id', 'group_name']
        group = AdminGroup.objects.all()
        pageGroup = paginator(group, request.GET.get('page'), 50)
        groupDict = [model_to_dict(g, fields=fields) for g in pageGroup]
        return JsonResponse({
            'status': True,
            'group_list': groupDict,
            'has_previous': pageGroup.has_previous(),
            'has_next': pageGroup.has_next()
        })
